package com.holystone.orca.common;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
import org.apache.log4j.Logger;

public class OrcaCacheManager {
	private static Logger logger = Logger.getLogger(OrcaCacheManager.class);
	private static CacheManager cacheManager;
	private static Cache orcaCache;
	static{
		cacheManager = CacheManager.create("src/main/resources/ehcache.xml");
		orcaCache = cacheManager.getCache("orcaCache");
	}
	
	public static void putCache(String key,Object value){
		Element element = new Element(key, value);
		orcaCache.put(element);
		logger.debug("插入缓存,key:"+key);
	}
	public static Object getCache(String key){
		Element element = orcaCache.get(key);
		if (element == null) {
			return null;
		}
		logger.debug("读取缓存,key:"+key);
		return element.getObjectValue();
	}
	public static void clearCache(){
		logger.debug("清空缓存!");
		orcaCache.removeAll();
	}
}
